package com.mh.rpc.consumer.loadbalance;

import java.util.ArrayList;
import java.util.List;

public class RoundRobin {
    private final List<ServerInfo> serverInfos = new ArrayList<>();

    private int index;

    public RoundRobin() {
        serverInfos.add(new ServerInfo("127.0.0.1", 8898));
        serverInfos.add(new ServerInfo("127.0.0.1", 8899));
    }

    public ServerInfo getServer() {
        ServerInfo serverInfo = serverInfos.get(index);
        index++;
        if (index >= serverInfos.size()) {
            index = 0;
        }
        return serverInfo;
    }

    public static void main(String[] args) {
        RoundRobin roundRobin = new RoundRobin();
        System.out.println(roundRobin);
    }
}
